--[[

	CAT 

]]
function ccR_Druid_Mangle()
	if ccrPlayerHasBuff(CAT_FORM)
	and ccrValidTarget()
	then
		if Player:IsBehind(Target) 
		and ccrPlayerHasSpell(SHRED) 
		then
			if SpellCanAttack(SHRED) then
				ccrCastAttack(SHRED)
				return
			end			
		else
			if SpellCanAttack(MANGLE) then
				ccrCastAttack(MANGLE)
				return
			end
		end
	end
	if ccrPlayerHasBuff(BEAR_FORM)
	and SpellCanAttack(MANGLE)
	then
		ccrCastAttack(MANGLE)
		return
	end
end

function ccR_Druid_Rake()
	if not ccrTargetHasDebuff(RAKE)
	and SpellCanAttack(RAKE)
	then
		ccrCastAttack(RAKE)
		return
	end
end

function ccR_Druid_Ferocious_Bite()
	local vComboPoint
	if ccrPlayerLevel() >= 10 and ccrPlayerLevel() <= 84 then
		if ccrTargetIsBoss() then
			vComboPoint = 4
		else
			vComboPoint = 3
		end
	end
	if ccrPlayerLevel() >= 85 then
		if ccrTargetIsBoss() then
			vComboPoint = 5
		else
			vComboPoint = 3
		end
	end
	if ccrComboPoints() < vComboPoint then
		ccR_Druid_Mangle()
		return
	else
		if SpellCanAttack(FEROCIOUS_BITE) then
			ccrCastAttack(FEROCIOUS_BITE)
			return
		end			
	end
end

function ccR_Druid_Rip()
	local vComboPoint
	if ccrPlayerLevel() >= 10 and ccrPlayerLevel() <= 84 then
		vComboPoint = 4
	end
	if ccrPlayerLevel() >= 85 then
		vComboPoint = 5
	end
	if ccrComboPoints() < vComboPoint then
		ccR_Druid_Mangle()
		return
	else
		if SpellCanAttack(RIP) then
			ccrCastAttack(RIP)
			return
		end			
	end
end

function ccR_Druid_Tigers_Fury()
	if ccrPlayerHasSpell(TIGERS_FURY)
	and	SpellIsReady(TIGERS_FURY)
	and ccrPlayerEnergy() <= 40
	and ccrPlayerIsInCombat()
	and ccrTargetIsWithinMeleeRange()
	and not ccrPlayerHasBuff(BERSERK)
	then
		ccrCast(TIGERS_FURY)
		return
	end
end

function ccR_Druid_Savage_Roar()
	if ccrPlayerHasBuff(CAT_FORM)
	and ccrPlayerHasSpell(SAVAGE_ROAR)
	then
		if ccrPlayerHasGlyph(127540) then -- Glyph of Savagery
			if ccrPlayerEnergy() >= 25
			and SpellIsReady(SAVAGE_ROAR_GLYPH)
			then
				ccrCast(SAVAGE_ROAR)
			end
		else
			if ccrComboPoints == 0 then
				ccR_Druid_Mangle()
			else
				if SpellIsReady(SAVAGE_ROAR) then
					ccrCast(SAVAGE_ROAR)
					return
				end
			end
		end
	end
end

function ccR_Druid_Thrash()
	if ccrPlayerHasBuff(CAT_FORM)
	and ccrPlayerHasSpell(THRASH_FERAL)
	and SpellIsReady(THRASH_FERAL)
	then
		ccrCast(THRASH_FERAL)
		return
	end
	if ccrPlayerHasBuff(BEAR_FORM)
	and ccrPlayerHasSpell(THRASH_BEAR)
	and SpellIsReady(THRASH_BEAR)
	then
		ccrCast(THRASH_BEAR)
		return	
	end
end

function ccR_Druid_Swipe()
	if ccrPlayerHasBuff(CAT_FORM)
	and ccrPlayerHasSpell(SWIPE_FERAL)
	and SpellIsReady(SWIPE_FERAL)
	then
		ccrCast(SWIPE_FERAL)
		return
	end
	if ccrPlayerHasBuff(BEAR_FORM)
	and ccrPlayerHasSpell(SWIPE_BEAR)
	and SpellIsReady(SWIPE_BEAR)
	then
		ccrCast(SWIPE_BEAR)
		return
	end
end

function ccR_Druid_Predatory_Swiftness(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local vUsePredatorySwiftness = ccRS["Druid_" .. specNumber .. "_UsePredatorySwiftness"]
	local vHealthToUsePS = ccRS["Druid_" .. specNumber .. "_PredatorySwiftnessHP"]
	if vUsePredatorySwiftness
	and ccrPlayerHealth() <= vHealthToUsePS
	and ccrPlayerHasBuff(PREDATORY_SWIFTNESS_PROC)
	and ccrPlayerHasSpell(HEALING_TOUCH)
	and ccrSpellIsReady(HEALING_TOUCH)
	then
		ccrCast(HEALING_TOUCH)
		return
	end
end

function ccR_Druid_Faerie_Fire(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local vUseFaerieFire = ccRS["Druid_" .. specNumber .. "_UseFaerieFire"]
	local vFAERIE_FIRE
	-- Faerie Swarm 
	if ccrPlayerHasTalent(106707) then
		vFAERIE_FIRE = 102355
	else
		vFAERIE_FIRE = FAERIE_FIRE
	end

	if vUseFaerieFire
	and SpellCanAttack(FAERIE_FIRE)
	then
		if ccrPlayerHasBuff(CAT_FORM)
		and not ccrTargetHasDebuff(vFAERIE_FIRE)
		then
			ccrCastAttack(vFAERIE_FIRE)
			return
		end

		if ccrPlayerHasBuff(BEAR_FORM) then
			ccrCastAttack(vFAERIE_FIRE)
			return
		end
	end
end

function ccR_Druid_Barkskin(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local vUseBarkskin = ccRS["Druid_" .. specNumber .. "_UseBarkskin"]
	local vBarkskinHP = ccRS["Druid_" .. specNumber .. "_BarkskinHP"]
	if vUseBarkskin
	and SpellIsReady(BARKSKIN)
	and ccrPlayerHealth() <= vBarkskinHP
	and ccrPlayerIsInCombat()
	then
		ccrCast(BARKSKIN)
		return
	end
end

function ccR_Druid_Berserk(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local vUseBerserk = ccRS["Druid_" .. specNumber .. "_UseBerserk"]
	local vBerserk
	if ccrPlayerHasBuff(CAT_FORM) then vBerserk = BERSERK_FERAL end
	if ccrPlayerHasBuff(BEAR_FORM) then vBerserk = BERSERK_BEAR end

	if vUseBerserk
	and SpellIsReady(vBerserk)
	and ccrPlayerIsInCombat()
	and ccrTargetIsWithinMeleeRange()
	then
		ccrCast(vBerserk)
		return
	end
end

function ccR_Druid_SurvivalInstincts(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local vUseSurvivalInstincts = ccRS["Druid_" .. specNumber .. "_UseSurvivalInstincts"]
	local vSurvivalInstinctsHP = ccRS["Druid_" .. specNumber .. "_SurvivalInstinctsHP"]
	if vUseSurvivalInstincts
	and ccrPlayerHasSpell(SURVIVAL_INSTINCTS)
	then
		if SpellIsReady(SURVIVAL_INSTINCTS)
		and ccrPlayerHealth() <= vSurvivalInstinctsHP
		and ccrPlayerIsInCombat()
		then
			ccrCast(SURVIVAL_INSTINCTS)
			return
		end
	end
end

function ccR_Druid_SkullBash(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local vUseSkullBash = ccRS["Druid_" .. specNumber .. "_UseSkullBash"]
	local vSkullBash 
	if ccrPlayerHasBuff(CAT_FORM) then vSkullBash = SKULL_BASH_FERAL end
	if ccrPlayerHasBuff(BEAR_FORM) then vSkullBash = SKULL_BASH_BEAR end
	if vUseSkullBash
	and SpellCanAttack(vSkullBash)
	and ccrTargetIsCastingOrChanneling()
	and ccrTargetIsInteruptable()
	then
		if ccrTargetIsChanneling() then
			ccrCast(vSkullBash)
			return
		end
		if ccrTargetIsCasting()
		and ccrTargetHasLeftOnCast(1)
		then
			ccrCast(vSkullBash)
			return
		end
	end
end

function ccR_Druid_Might_Of_Ursoc(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local vUseMightOfUrsoc = ccRS["Druid_" .. specNumber .. "_UseMightOfUrsoc"]
	local vMightOfUrsocHP = ccRS["Druid_" .. specNumber .. "_MightOfUrsocHP"]
	if vUseMightOfUrsoc
	and ccrPlayerHasSpell(MIGHT_OF_URSOC)
	and SpellIsReady(MIGHT_OF_URSOC)
	and ccrPlayerHealth() <= vMightOfUrsocHP
	and ccrPlayerIsInCombat()
	then
		ccrCast(MIGHT_OF_URSOC)
		return
	end
end

--[[

	BEAR

]]

function ccR_Druid_Maul()
	if SpellCanAttack(MAUL) then
		ccrCastAttack(MAUL)
		return
	end
end

function ccR_Druid_Bear_Hug()
	if ccrPlayerHasSpell(BEAR_HUG)
	and SpellCanAttack(BEAR_HUG)
	and not ccrTargetIsBoss()
	then
		ccrCastAttack(BEAR_HUG)
		return
	end
end